//
//  LoginController.m
//  PaiQuan
//
//  Created by Mac on 16/7/15.
//  Copyright © 2016年 huigu. All rights reserved.
//

#import "LoginController.h"
#import "ANBlurredImageView.h"
#import "ForgetPassWordController.h"
@interface LoginController ()<UITextFieldDelegate>
//背景图

@property(nonatomic,strong)ANBlurredImageView *blackGroundView;
//容器试图
@property(nonatomic,strong)UIView *contentView;
//手机图片
@property(nonatomic,strong)UIImageView *IphoneImgView;
//手机输入框
@property(nonatomic,strong)UITextField *IphoneTF;
//分割线
@property(nonatomic,strong)UIView *lineView1;
@property(nonatomic,strong)UIView *lineView2;
//密码试图
@property(nonatomic,strong)UIImageView *PassWordImgView;
//密码输入框
@property(nonatomic,strong)UITextField *passwordTF;
//进入牌圈按钮
@property(nonatomic,strong)UIButton *loginBtn;
//注册
@property(nonatomic,strong)UIButton *registerBtn;
//忘记密码
@property(nonatomic,strong)UIButton *forgetBtn;
//顶部图片
@property(nonatomic,strong)UIImageView *headerImgView;
@property(nonatomic,assign)UIActivityIndicatorView *spinner;



@end

@implementation LoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
-(void)viewDidAppear:(BOOL)animated{
   [super viewDidAppear:animated];

    [UIView animateWithDuration:3.5f animations:^{
        
        self.contentView.alpha =1.0f;
        self.headerImgView.alpha =1.0f;
    }];

      [UIView animateWithDuration:2.0f animations:^{
          [self.blackGroundView blurOutAnimationWithDuration:2.0f];

          self.blackGroundView.transform = CGAffineTransformMakeScale(0.9f, 0.9f);
          
  
          
      } completion:^(BOOL finished) {
          [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:1 options: UIViewAnimationOptionCurveLinear   animations:^{
              self.blackGroundView.animationDuration = 1;
               self.blackGroundView.animationImages =  [self.blackGroundView.framesArray subarrayWithRange:NSMakeRange(0, 10)];
              [self.blackGroundView setImage:self.blackGroundView.animationImages.lastObject];
              [ self.blackGroundView startAnimating];
               self.blackGroundView.transform = CGAffineTransformScale(self.blackGroundView.transform, 1.05, 1.05);
              
            
          } completion:^(BOOL finished) {
              [UIView animateWithDuration:0.5  animations:^{
                  self.blackGroundView.animationDuration = 0.5;
                  
                  // Set our reverse image array.
                  self.blackGroundView.animationImages =  [self.blackGroundView.framesReverseArray subarrayWithRange:NSMakeRange(19, 5)];
                  self.blackGroundView.image = self.blackGroundView.animationImages.lastObject;
                  [ self.blackGroundView startAnimating];

                  self.blackGroundView.transform = CGAffineTransformScale(self.blackGroundView.transform, 0.999, 0.999);
                  
              } completion:^(BOOL finished) {

              
                  [UIView animateWithDuration:0.5f delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:0.4 options:UIViewAnimationOptionCurveLinear   animations:^{
                      
                      self.contentView.transform = CGAffineTransformMakeTranslation(0, -RATIO(472));
                      [self.IphoneTF becomeFirstResponder];
                      self.headerImgView.hidden = YES;
                  } completion:^(BOOL finished) {
                  
                  }];

                  
              }];
              
              
          }];
          
      }];
   

  
    

    
}

-(void)backgroudTransChange{
    
}
-(void)backgroudImageChange{
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.titleView.hidden = YES;
    [self setUPUI];
    [self setUPCon];
    [self.blackGroundView setFramesCount:30];
    [self.blackGroundView setBlurAmount:1];

    
    

}
-(void)setUPUI{
  
    [self.view addSubview:self.blackGroundView];
    [self.view addSubview:self.contentView];
    [self.view addSubview:self.headerImgView];
    [self.contentView addSubview:self.IphoneImgView];
    [self.contentView addSubview:self.IphoneTF];
    [self.contentView addSubview:self.lineView1];
    [self.contentView addSubview:self.lineView2];
    [self.contentView addSubview:self.PassWordImgView];
    [self.contentView addSubview:self.passwordTF];
    [self.contentView addSubview:self.loginBtn];
    [self.contentView addSubview:self.registerBtn];
    [self.contentView addSubview:self.forgetBtn];
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}
-(void)setUPCon{
    [self.blackGroundView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self.view);
        make.width.equalTo(ScreenW*1.1);
        make.height.equalTo(ScreenH*1.1);
    }];
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.top).offset(RATIO(750));
        make.bottom.equalTo(self.view.bottom);
        make.left.equalTo(self.view.left);
        make.width.equalTo(self.view.width);
        
    }];
    [self.IphoneImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(RATIO(138));
        make.top.equalTo(self.contentView.top);
       make.width.height.equalTo(RATIO(40));
    }];
    [self.IphoneTF makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.IphoneImgView.right).offset(RATIO(44));
        make.centerY.equalTo(self.IphoneImgView);
        
    }];
    
    [self.lineView1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.IphoneImgView);
        make.top.equalTo(self.contentView.top).offset(RATIO(60));
        make.width.equalTo(RATIO(502));
        make.height.equalTo(RATIO(2));
    }];
    [self.PassWordImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(RATIO(138));
        make.top.equalTo(self.contentView.top).offset(RATIO(88));
        make.width.height.equalTo(RATIO(40));


    }];
    [self.passwordTF makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.PassWordImgView.right).offset(RATIO(44));
        make.centerY.equalTo(self.PassWordImgView);
    }];
    [self.lineView2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.top).offset(RATIO(156));
         make.left.equalTo(self.contentView.left).offset(RATIO(124));
        make.width.equalTo(RATIO(502));
        make.height.equalTo(RATIO(2));

        
        
    }];
    [self.loginBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView2.left);
        make.top.equalTo(self.lineView2.bottom).offset(RATIO(60));
        make.width.equalTo(RATIO(502));
        make.height.equalTo(RATIO(72));
        
        
    }];
    [self.registerBtn makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(self.lineView2.left);
        make.width.equalTo(RATIO(502));
        make.height.equalTo(RATIO(72));
        make.top.equalTo(self.loginBtn.bottom).offset(RATIO(24));


    }];
    [self.forgetBtn makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.bottom).offset(-RATIO(40));
        make.centerX.equalTo(self.contentView.centerX);
        
        
    }];
    [self.headerImgView makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerX.centerY.equalTo(self.view);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark --懒加载
-(ANBlurredImageView*)blackGroundView{
    if (!_blackGroundView) {
        _blackGroundView = [[ANBlurredImageView alloc] init];
        _blackGroundView.baseImage = PQIMG(@"login");
        _blackGroundView.userInteractionEnabled = NO;
        _blackGroundView.image = PQIMG(@"login");
        
    }
    
    return _blackGroundView;
}
-(UIView*)contentView{
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        
        _contentView.alpha = 0.0f;
    }
    
    return _contentView;
    
    
}
-(UIImageView*)IphoneImgView{
    if (!_IphoneImgView) {
        _IphoneImgView = [[UIImageView alloc] init];
    
        _IphoneImgView.image = PQIMG(@"iphone6");
    }
    
    return   _IphoneImgView;
}
-(UITextField *)IphoneTF{
    if (!_IphoneTF) {
        _IphoneTF = [[UITextField alloc] init];
        _IphoneTF.backgroundColor = [UIColor clearColor];
        _IphoneTF.delegate = self;
        //_account.placeholder=[NSString stringWithFormat:@"Email"];
        UIColor *color = [UIColor whiteColor];
        _IphoneTF.attributedPlaceholder = [[NSAttributedString alloc]
                                                   initWithString:@"请输入您的手机号码"
                                                   attributes:@{NSForegroundColorAttributeName : color}];
        _IphoneTF.textColor = [UIColor whiteColor];
        _IphoneTF.userInteractionEnabled = YES;
       
        _IphoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _IphoneTF.adjustsFontSizeToFitWidth = YES;
        [_IphoneTF addTarget:self
                              action:@selector(textFieldDidChange:)
                    forControlEvents:UIControlEventEditingChanged];
        _IphoneTF.keyboardType = UIKeyboardTypeNumberPad;
        _IphoneTF.returnKeyType = UIReturnKeyGo;

    }
    return _IphoneTF;
    
}
-(UIView*)lineView1{
    if (!_lineView1) {
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor whiteColor];
        
    }
    return _lineView1;
}
-(UIView*)lineView2{
    if (!_lineView2) {
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor whiteColor];
        
    }
    return _lineView2;
}
-(UIImageView*)PassWordImgView{
    if (!_PassWordImgView) {
        _PassWordImgView = [[UIImageView alloc] init];
        
        _PassWordImgView.image = PQIMG(@"password");
    }
    
    return   _PassWordImgView;
}
-(UITextField*)passwordTF{
    if (!_passwordTF) {
        _passwordTF = [[UITextField alloc] init];
        _passwordTF.textColor = [UIColor whiteColor];
        _passwordTF.returnKeyType = UIReturnKeyDone;
        _passwordTF.secureTextEntry = YES;
//        _passwordTF.delegate = self;
       
         UIColor *color = [UIColor whiteColor];
        _passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        _passwordTF.attributedPlaceholder = [[NSAttributedString alloc]
                                                   initWithString:@"密码"
                                                   attributes:@{NSForegroundColorAttributeName : color}];

    }
    
    return _passwordTF;
    
    
}
-(UIButton*)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [[UIButton alloc] init];
        [_loginBtn setBackgroundColor:RGB(158, 129, 67)];
        [_loginBtn setTitle:@"进入牌圈" forState:UIControlStateNormal];
        [_loginBtn setTitleColor: [UIColor whiteColor] forState:UIControlStateNormal];
        
        _loginBtn.titleLabel.font = FONT(17);
        [_loginBtn addTarget:self
                        action:@selector(actionLogin:)
              forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}
-(UIButton*)registerBtn{
    if (!_registerBtn) {
        _registerBtn = [[UIButton alloc] init];
        _registerBtn.backgroundColor = RGBA(216, 216, 216, 0.9);
        [_registerBtn setTitle:@"快速注册" forState:UIControlStateNormal];
        [_registerBtn setTitleColor: RGB(102, 102, 102) forState:UIControlStateNormal];
        
        _registerBtn.titleLabel.font = FONT(17);
        [_registerBtn addTarget:self
                      action:@selector(actionregister:)
            forControlEvents:UIControlEventTouchUpInside];
    }
    return _registerBtn;
}
-(UIButton*)forgetBtn{
    if (!_forgetBtn) {
        _forgetBtn = [[UIButton alloc] init];
       
        [_forgetBtn setTitle:@"忘记密码？" forState:UIControlStateNormal];
        [_forgetBtn setTitleColor: RGB(232, 232, 232) forState:UIControlStateNormal];
        
        _forgetBtn.titleLabel.font = FONT(13);
        [_forgetBtn addTarget:self
                         action:@selector(forgetPassWord:)
               forControlEvents:UIControlEventTouchUpInside];
    }
    return _forgetBtn;
}
-(UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc] init];
        _headerImgView.image = PQIMG(@"headerImg");
        _headerImgView.alpha = 0.0f;
    }
    return _headerImgView;
}
#pragma mark --按钮的点击事件
-(void)actionLogin:(UIButton*)sender{
    
    
}
-(void)actionregister:(UIButton*)sender{
    
}
-(void)forgetPassWord:(UIButton*)sender{
    NSLog(@"点击了");
    ForgetPassWordController *forgetPassVC =[[ForgetPassWordController alloc] init];
    
    [self.navigationController pushViewController:forgetPassVC animated:YES];
    
}

- (void)textFieldDidChange:(UITextField *)textField{
   


}
@end
